﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WHC.Hotel.Entity;
using WHC.Hotel.BLL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.UI
{
    public partial class FrmTransferOrder : BaseForm
    {
        public FrmTransferOrder()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.None;

            #region 检查目标房间有效性
            if (this.txtTargetRoom.Text.Trim().Length == 0)
            {
                MessageUtil.ShowTips("请输入目标房间");
                this.txtTargetRoom.Focus();
                return;
            }

            RoomInfo targetRoom = BLLFactory<Room>.Instance.FindByRoomNo(this.txtTargetRoom.Text);
            if (targetRoom != null)
            {
                if (targetRoom.Status != RoomStatus.住净房 && 
                    targetRoom.Status != RoomStatus.住脏房)
                {
                    MessageUtil.ShowTips("目标房间处于非消费状态，转单失败");
                    this.txtTargetRoom.Focus();
                    return;
                }

                if (targetRoom.RoomNo == this.lblRoomNo.Text)
                {
                    MessageUtil.ShowTips("目标房间和原房间不能为同一房间，转单失败");
                    this.txtTargetRoom.Focus();
                    return;
                }
            }
            else
            {
                MessageUtil.ShowTips("目标房间不存在，请重新输入");
                this.txtTargetRoom.Focus();
                return;
            } 
            #endregion

            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtTargetRoom_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOK_Click(null, null);
            }
        }
    }
}
